﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace FDSimpleModelGenerator.Common
{
    /// <summary>
    /// 扩展
    /// </summary>
    public static class ObjExtensions
    {
        /// <summary>
        /// 是否为空
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static bool IsNullOrEmpty(this string str)
        {
            return string.IsNullOrEmpty(str) || str.Trim().Length == 0;
        }

        /// <summary>
        /// 替换 整个单词
        /// </summary>
        /// <param name="original"></param>
        /// <param name="wordToFind"></param>
        /// <param name="replacement"></param>
        /// <param name="regexOptions"></param>
        /// <returns></returns>
        public static string ReplaceWholeWord(this string original, string wordToFind, string replacement,
             RegexOptions regexOptions = RegexOptions.None)
        {
            string pattern = string.Format(@"\b{0}\b", wordToFind);
            string ret = Regex.Replace(original, pattern, replacement, regexOptions);
            return ret;
        }

        /// <summary>
        /// 加密串
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string ToEncryptString(this string str)
        {
            return EncryptUtil.Encrypt(str);
        }
    }
}
